package com.zut.hospital.controller.pharmacy;

import com.alibaba.fastjson.JSONObject;
import com.zut.hospital.service.pharmacy.SupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: hos-test
 * @description: 供应商
 * @author: 杨曼珍
 * @create: 2019-06-07 16:07
 **/
@Controller
@RequestMapping("/hospital")
public class SupController {
    @Autowired
    SupService supService;


    @ResponseBody
    @RequestMapping(value = "/allSup",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public String getAllSup(){
     return supService.getAllSup();
    }

    @ResponseBody
    @RequestMapping(value = "/updateSup",produces = "application/json;charset=utf-8",method = RequestMethod.POST)
    public String updateSup(@RequestBody String data){
        String field=JSONObject.parseObject(data).getString("field");
        String value=JSONObject.parseObject(data).getString("value");
        int id=JSONObject.parseObject(data).getInteger("id");
        return supService.updateSup(id,field,value);
    }

    @ResponseBody
    @RequestMapping(value = "/addSup",produces = "application/json;charset=utf-8",method = RequestMethod.POST)
    public String addSup(@RequestBody String data){
        String name=JSONObject.parseObject(data).getString("name");
        String remark=JSONObject.parseObject(data).getString("remark");
        String contract=JSONObject.parseObject(data).getString("contract");
        return supService.addSup(name,contract,remark);
    }
}
